package cn.com.server.config;

import java.util.Locale;

import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.context.request.RequestContextListener;

import cn.com.server.common.util.SpringUtil;

@Configuration
public class I18nConfig {
	
	@Bean(name = "messageSource")
	public ResourceBundleMessageSource myMessageSource(){
		ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
		resourceBundleMessageSource.setBasename("messages/messages");
		resourceBundleMessageSource.setUseCodeAsDefaultMessage(true);
        return resourceBundleMessageSource;
    }
	
    @Bean(name = "localeResolver")
    public MyLocaleResolver myLocaleResolver(){
        System.out.println("#####cookieLocaleResolver---create");
        MyLocaleResolver myLocaleResolver = new MyLocaleResolver();
        myLocaleResolver.setDefaultLocale(Locale.ENGLISH);
        System.out.println("#####cookieLocaleResolver:");
        return myLocaleResolver;
    }
    
    @Bean
    public ServletListenerRegistrationBean<RequestContextListener> servletListenerRegistrationBean(){
        ServletListenerRegistrationBean<RequestContextListener> servletListenerRegistrationBean = new ServletListenerRegistrationBean<RequestContextListener>();
        servletListenerRegistrationBean.setListener(new RequestContextListener());
        return servletListenerRegistrationBean;
    }
    
    @Bean(name="SpringUtil")
    public SpringUtil mySpringUtil(){
    	SpringUtil su = new SpringUtil();
        return su;
    }
}
